<%@page import="com.fractalist.man.constants.ManConstants"%>
<%@page import="com.fractalist.base.core.constants.SystemConstants"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	pageContext.setAttribute("baseweburl",
			SystemConstants.UPLOAD_WEB_URL);
	pageContext.setAttribute("adsTypeMap", ManConstants.ADS_TYPE_MAP);
	pageContext.setAttribute("adsClassMap", ManConstants.ADS_CLASS_MAP);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>文章</title>
<link rel="stylesheet" href="${ctx }/css/styles.css" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.form.js"></script>
<jsp:include page="/common/jscalendar.jsp"></jsp:include>
</head>
<body style="overflow-y: scroll;">
	<script>
		var baseweburl = "${baseweburl}";
		function createAds() {
			var type = $("#types").val();
			var adsClass = $("#adsClass").val();
			var title = $("#title").val();
			var adsUrl = $("#adsUrl").val();
			var adsHtml = $("#adsHtml").val();
			var adsPic = $("#adsPic").val();
			if (type == "") {
				alert("请输入广告的标题");
				return;
			}
			$.post("${ctx}/manager/createAds.action", {
				type : type,
				adsClass : adsClass,
				title : title,
				adsUrl : adsUrl,
				adsHtml : adsHtml,
				adsId : $("#adsId").val(),
				adsPic : adsPic
			}, function(data) {
				location.href = "${ctx}/manage/viewAdsPage.action";
			})
		}

		function uploadImage() {
			var options = {
				url : '${ctx}/manager/uploadImgBase.action',
				type : "POST",
				dataType : "json",
				success : function(result) {
					var code = result.data.code;
					var url = result.data.url;
					if (code == 0) {
						$("#imgDiv").html($("<img src='"+ url +"' />"));
						$("#adsPic").val(url);
					}
				}
			};
			$("#uploadForm").ajaxSubmit(options);
		}

		var articleTypeMap = {};
		<c:forEach items="${articleTypeMap}" var="entry">
		articleTypeMap["${entry.key}"] = "${entry.value}";
		</c:forEach>
	</script>
	<div id="wrapper">
		<div id="content_wrap">
			<div class="tabs_content">
				<div class="active_tab" id="tab1"></div>
				<div id="table_wrapper" style="width: 100%; overflow: auto;">
					<form id="uploadForm" method="post" enctype="multipart/form-data">
						<table class="table" cellpadding="0" cellspacing="0">
							<input type="hidden" name="adsId" id="adsId" value="${ads.id }" />

							<tr>
								<td>广告分类</td>
								<td><select id="types" name="types">
										<c:forEach items="${adsTypeMap}" var="entry">
											<option value="${entry.key }"
												<c:if test="${entry.key == ads.id }">selected="selected"</c:if>>${entry.value
												}</option>
										</c:forEach>
								</select></td>
							</tr>
							<tr>
								<td>广告类型</td>
								<td><select id="adsClass" name=""adsClass"">
										<c:forEach items="${adsClassMap}" var="entry">
											<option value="${entry.key }"
												<c:if test="${entry.key == ads.class }">selected="selected"</c:if>>${entry.value
												}</option>
										</c:forEach>
								</select></td>
							</tr>
							<tr>
								<td>广告标题</td>
								<td><input id="title" name="title" style="width: 600px;"
									value="${ads.title }" /></td>
							</tr>
							<tr>
								<td>上传图片</td>
								<td><input id="fileid" type="file" value="选择上传图片"
									name="fujianFile" onchange="uploadImage()" /><font color="red">*上传图片需要一定时间，请耐心等待</font><input
									type="hidden" id="adsPic" name="adsPic"
									values="${ads.pic }" />
									<div id="imgDiv">
										<c:if test="${!empty ads.pic }">
											<img src="${ads.pic }" />
										</c:if>
									</div></td>
							</tr>
							<tr>
								<td>输入链接</td>
								<td><input id="adsUrl" name="adsUrl" size=50
									value="${ads.url }" /></td>
							</tr>
							<tr>
								<td>输入html内容</td>
								<td><textarea id="adsHtml" name="adsHtml"
										style="width: 600px; height: 400px;">${ads.html }</textarea></td>
							</tr>
							<tr>
								<td></td>
								<td><input type="button" value="提交广告"
									onclick="createAds();" /></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		</div>
	</div>
	</div>
</body>
</html>

